package com.gscitysfy.cus.drain.modules.pipe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.common.service.IFileService;
import com.gscitysfy.cus.drain.modules.pipe.entity.DrainPipeNetworkJob;
import com.gscitysfy.cus.drain.modules.pipe.entity.DrainPipeNetworkReport;
import com.gscitysfy.cus.drain.modules.pipe.service.IDrainPipeNetworkJobService;
import com.gscitysfy.cus.drain.modules.pipe.vo.DrainPipeNetworkJobVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-11-15 10:50:04
 */
@RestController
@RequestMapping("/pipe/job")
public class DrainPipeNetworkJobController {
    @Autowired
    IFileService fileService;
    @Autowired
    IDrainPipeNetworkJobService drainPipeNetworkJobService;

    /**
     * @description: 检测任务管理列表
     */
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType"),
    })
    @PostMapping("/list")
    public Result<Object> list(@RequestBody DrainPipeNetworkJobVo drainPipeNetworkJobVo) {
        Page<DrainPipeNetworkJob> page = new Page<>();
        if(Objects.isNull(drainPipeNetworkJobVo)){
            drainPipeNetworkJobVo =  new DrainPipeNetworkJobVo();
        }
        page.setCurrent(drainPipeNetworkJobVo.getCurrent());
        page.setSize(drainPipeNetworkJobVo.getSize());
        return Result.content(drainPipeNetworkJobService.getByPage(page, drainPipeNetworkJobVo));
    }




    /**
     * 详情
     */
    @GetMapping("/detail")
    @Operation(summary = "详情")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result detail(Long  id) {
        return   Result.content(drainPipeNetworkJobService.detail(id));
    }


    /**
     * 小程序任务列表 0 未开始    1  进行中    2 已完成
     */
    @GetMapping("/jobXcx")
    @Operation(summary = "小程序任务列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result<Object> jobXcx(Long  size,Long  current,String   keyWord,String  orderState) {
        Page<DrainPipeNetworkJob> page = new Page<>();
        page.setCurrent(current);
        page.setSize(size);
        return   Result.content(drainPipeNetworkJobService.jobXcx(page,orderState,keyWord));
    }

    /**
     * 通过任务id管网列表
     */
    @GetMapping("/detailXcxGw")
    @Operation(summary = "管网列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result detailXcxGw(Long  id,String  orderState) {
        return   Result.content(drainPipeNetworkJobService.detailXcxGw(id,orderState));
    }





    /**
     * 新增多个检测报告模板
     */
    @PostMapping("/addReport")
    @Operation(summary = "新增检测报告模板")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result addReport(@RequestBody List<DrainPipeNetworkReport> DrainPipeNetworkReports) {
        return   Result.content(drainPipeNetworkJobService.addReport(DrainPipeNetworkReports));
    }

    /**
     * 查询检测报告模板列表
     */
    @GetMapping("/listReport")
    @Operation(summary = "查询检测报告模板列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result listReport() {
        return   Result.content(drainPipeNetworkJobService.listReport());
    }



    /**
     * 通过管网id查询缺陷
     */
    @GetMapping("/detailFlawByPipeId")
    @Operation(summary = "通过管网id查询缺陷")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result detailFlawByPipeId(Long id) {
        return   Result.content(drainPipeNetworkJobService.detailFlawByPipeId(id));
    }



    /**
     * 通过管网id赋值开始检测status=1和完成检测status=2，改变状态
     */
    @GetMapping("/startAndFinishPipe")
    @Operation(summary = "通过管网id赋值开始检测和完成检测，改变状态")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result startAndFinishPipe(Long id,Integer status,Long jobId) {
        return   Result.content(drainPipeNetworkJobService.startAndFinishPipe(id,status,jobId));
    }


    /**
     * 通过任务id赋值，改变状态
     */
    @GetMapping("/startAndFinishJob")
    @Operation(summary = "通过管网id赋值开始检测和完成检测，改变状态")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmJobPipeType")
    })
    public Result startAndFinishJob(Long id,Integer status) {
        return   Result.content(drainPipeNetworkJobService.startAndFinishJob(id,status));
    }




    /**
     * 通过id查file列表
     */
    @GetMapping("/listFile")
    @Operation(summary = "通过id查file列表")
    public Result listFile(String id) {
        return   Result.content(fileService.getFileListByIds(id));
    }




}
